import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author Jiange
 * @create 2021-07-16-13:07
 */
public class CyclicBarrierDemo {
    public static void main(String[] args) {
        //在够了数量 执行runable里
        CyclicBarrier barrier = new CyclicBarrier(7, () -> {
            System.out.println("神龙出现");
        });
        for (int i = 0; i < 7; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName());
                try {
                    barrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            },String.valueOf(i)).start();
        }
    }
}
